package com.aprivate.kn.ratingsystem.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.aprivate.kn.ratingsystem.daoBean.Interviewee;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "INTERVIEWEE".
*/
public class IntervieweeDao extends AbstractDao<Interviewee, Long> {

    public static final String TABLENAME = "INTERVIEWEE";

    /**
     * Properties of entity Interviewee.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, long.class, "id", true, "_id");
        public final static Property ProductInfoId = new Property(1, long.class, "productInfoId", false, "PRODUCT_INFO_ID");
        public final static Property Name = new Property(2, String.class, "name", false, "NAME");
        public final static Property Address = new Property(3, String.class, "address", false, "ADDRESS");
        public final static Property Phone = new Property(4, String.class, "phone", false, "PHONE");
        public final static Property Email = new Property(5, String.class, "email", false, "EMAIL");
        public final static Property Type = new Property(6, int.class, "type", false, "TYPE");
    }

    private Query<Interviewee> project_AuditLeaderIntervieweesQuery;
    private Query<Interviewee> project_ByAuditLeaderIntervieweesQuery;

    public IntervieweeDao(DaoConfig config) {
        super(config);
    }
    
    public IntervieweeDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"INTERVIEWEE\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ," + // 0: id
                "\"PRODUCT_INFO_ID\" INTEGER NOT NULL ," + // 1: productInfoId
                "\"NAME\" TEXT," + // 2: name
                "\"ADDRESS\" TEXT," + // 3: address
                "\"PHONE\" TEXT," + // 4: phone
                "\"EMAIL\" TEXT," + // 5: email
                "\"TYPE\" INTEGER NOT NULL );"); // 6: type
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"INTERVIEWEE\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, Interviewee entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
        stmt.bindLong(2, entity.getProductInfoId());
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String address = entity.getAddress();
        if (address != null) {
            stmt.bindString(4, address);
        }
 
        String phone = entity.getPhone();
        if (phone != null) {
            stmt.bindString(5, phone);
        }
 
        String email = entity.getEmail();
        if (email != null) {
            stmt.bindString(6, email);
        }
        stmt.bindLong(7, entity.getType());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Interviewee entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
        stmt.bindLong(2, entity.getProductInfoId());
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }
 
        String address = entity.getAddress();
        if (address != null) {
            stmt.bindString(4, address);
        }
 
        String phone = entity.getPhone();
        if (phone != null) {
            stmt.bindString(5, phone);
        }
 
        String email = entity.getEmail();
        if (email != null) {
            stmt.bindString(6, email);
        }
        stmt.bindLong(7, entity.getType());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.getLong(offset + 0);
    }    

    @Override
    public Interviewee readEntity(Cursor cursor, int offset) {
        Interviewee entity = new Interviewee( //
            cursor.getLong(offset + 0), // id
            cursor.getLong(offset + 1), // productInfoId
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // name
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // address
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // phone
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // email
            cursor.getInt(offset + 6) // type
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Interviewee entity, int offset) {
        entity.setId(cursor.getLong(offset + 0));
        entity.setProductInfoId(cursor.getLong(offset + 1));
        entity.setName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setAddress(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setPhone(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setEmail(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setType(cursor.getInt(offset + 6));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(Interviewee entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(Interviewee entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(Interviewee entity) {
        throw new UnsupportedOperationException("Unsupported for entities with a non-null key");
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "auditLeaderInterviewees" to-many relationship of Project. */
    public List<Interviewee> _queryProject_AuditLeaderInterviewees(long productInfoId) {
        synchronized (this) {
            if (project_AuditLeaderIntervieweesQuery == null) {
                QueryBuilder<Interviewee> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ProductInfoId.eq(null));
                project_AuditLeaderIntervieweesQuery = queryBuilder.build();
            }
        }
        Query<Interviewee> query = project_AuditLeaderIntervieweesQuery.forCurrentThread();
        query.setParameter(0, productInfoId);
        return query.list();
    }

    /** Internal query to resolve the "byAuditLeaderInterviewees" to-many relationship of Project. */
    public List<Interviewee> _queryProject_ByAuditLeaderInterviewees(long productInfoId) {
        synchronized (this) {
            if (project_ByAuditLeaderIntervieweesQuery == null) {
                QueryBuilder<Interviewee> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ProductInfoId.eq(null));
                project_ByAuditLeaderIntervieweesQuery = queryBuilder.build();
            }
        }
        Query<Interviewee> query = project_ByAuditLeaderIntervieweesQuery.forCurrentThread();
        query.setParameter(0, productInfoId);
        return query.list();
    }

}
